Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set a default and max ttl for redis keys #38562

Merged
merged 1 commit into from
Feb 23, 2024
Merged

set a default and max ttl for redis keys #38562

merged 1 commit into from
Feb 23, 2024

Conversation

icewind1991
Copy link
Member

having infinite TTL can lead to leaked keys as the prefix changes with version upgrades

@icewind1991 icewind1991 added the 3. to review Waiting for reviews label May 31, 2023
@icewind1991 icewind1991 added this to the Nextcloud 28 milestone May 31, 2023
@icewind1991 icewind1991 requested review from a team, ArtificialOwl, blizzz and nfebe and removed request for a team May 31, 2023 15:41
Copy link
Member

@blizzz blizzz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be mentioned in developer documentation as well.

@ChristophWurst ChristophWurst added the pending documentation This pull request needs an associated documentation update label May 31, 2023
@ChristophWurst ChristophWurst requested a review from kesselb May 31, 2023 18:47
@ChristophWurst
Copy link
Member

\OCP\ICache::set says int $ttl Time To Live in seconds. Defaults to 60*60*24

@ChristophWurst
Copy link
Member

I think it would be reasonable to also define an upper bound for TTL. Like a cache key can only exist for three months.

@camilasan
Copy link
Member

Could this applied as a patch in 24.0.7?

@icewind1991 icewind1991 changed the title set a default ttl for redis keys of 1 month set a default and max ttl for redis keys Jun 2, 2023
@icewind1991
Copy link
Member Author

Switched the default to 1 day as per the interface docs and added a max of 1 month

return $this->getCache()->setex($this->getPrefix() . $key, $ttl, $value);
} else {
return $this->getCache()->set($this->getPrefix() . $key, $value);
if ($ttl === 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m a tiny bit worried that we may have code path not sending an int in $ttl since it is not strong typed, so here passing '0' would still result in infinite TTL I think?
Not sure if this worry is justified.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We were already checking for an int, I'd say LGTM

@skjnldsv skjnldsv mentioned this pull request Nov 1, 2023
This was referenced Nov 6, 2023
This was referenced Nov 14, 2023
@blizzz blizzz modified the milestones: Nextcloud 28, Nextcloud 29 Nov 23, 2023
@skjnldsv skjnldsv removed the 3. to review Waiting for reviews label Feb 23, 2024
@skjnldsv skjnldsv added the 4. to release Ready to be released and/or waiting for tests to finish label Feb 23, 2024
having infinite TTL can lead to leaked keys as the prefix changes with version upgrades

Signed-off-by: Robin Appelman <robin@icewind.nl>
@skjnldsv skjnldsv enabled auto-merge February 23, 2024 14:41
@skjnldsv skjnldsv merged commit 18434d1 into master Feb 23, 2024
160 checks passed
@skjnldsv skjnldsv deleted the redis-default-ttl branch February 23, 2024 17:37
@blizzz blizzz mentioned this pull request Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4. to release Ready to be released and/or waiting for tests to finish pending documentation This pull request needs an associated documentation update
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants